package com.cooper.service.seller;


import java.util.Collections;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cooper.dao.seller.DesignerApplyDAO;
import com.cooper.entity.DesignerApplyDo;
import com.cooper.pagination.PageInfo;
import com.cooper.pagination.PageResult;
import com.cooper.vo.DesignerApplyVo;

@Service
public class DesignerApplyService {
	
	protected Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	private DesignerApplyDAO designerApplyDAO;
	
	public Long createDesignerApply(DesignerApplyDo designerApplyDo){
		Long id = 0L;
		try {
			id = designerApplyDAO.addDesigner(designerApplyDo);
		} catch (Exception e) {
			logger.error("DesignerApplyService-createDesignerApply-error", e);
		}
		return id;
	}
	
	public void updateDesigner(DesignerApplyDo designerApplyDo){
		try {
			designerApplyDAO.updateDesignerApply(designerApplyDo);
		} catch (Exception e) {
			logger.error("DesignerApplyService-updateDesigner-error", e);
		}
	}
	
	public DesignerApplyDo findDesignerApplyById(Long id){
		try {
			return designerApplyDAO.getDesignerApply(id);
		} catch (Exception e) {
			logger.error("DesignerApplyService-findDesignerApplyById-error", e);
		}
		return null;
	}
	
	public DesignerApplyDo findDesignerApplyByUserId(Long userId,String status){
		try {
			return designerApplyDAO.getDesignerApplyByUserId(userId,status);
		} catch (Exception e) {
			logger.error("DesignerApplyService-findDesignerApplyByUserId-error", e);
		}
		return null;
	}
	
	
	
	@SuppressWarnings("unchecked")
	public PageResult<DesignerApplyVo> queryForList(DesignerApplyVo searchVo, PageInfo pageInfo) throws Exception{
		int rowCount = designerApplyDAO.queryDesignerApplyCount(searchVo);
		pageInfo.setRowCount(rowCount);
		if(0 == rowCount){
			return new PageResult<DesignerApplyVo>(Collections.EMPTY_LIST, pageInfo);
		}
		List<DesignerApplyVo> dataList = this.designerApplyDAO.queryForList(searchVo, pageInfo);
		return new PageResult<DesignerApplyVo>(dataList, pageInfo);
	}
}
